package com.video.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.system.domain.VideoAdvertising;
import com.video.system.service.IVideoAdvertisingService;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 广告Controller
 * 
 * @author lyh
 * @date 2021-07-31
 */
@RestController
@RequestMapping("/system/advertising")
public class VideoAdvertisingController extends BaseController
{
    @Autowired
    private IVideoAdvertisingService videoAdvertisingService;

    /**
     * 查询广告列表
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoAdvertising videoAdvertising)
    {
        startPage();
        List<VideoAdvertising> list = videoAdvertisingService.selectVideoAdvertisingList(videoAdvertising);
        return getDataTable(list);
    }

    /**
     * 导出广告列表
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:export')")
    @Log(title = "广告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VideoAdvertising videoAdvertising)
    {
        List<VideoAdvertising> list = videoAdvertisingService.selectVideoAdvertisingList(videoAdvertising);
        ExcelUtil<VideoAdvertising> util = new ExcelUtil<VideoAdvertising>(VideoAdvertising.class);
        return util.exportExcel(list, "广告数据");
    }

    /**
     * 获取广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:query')")
    @GetMapping(value = "/{advertisingId}")
    public AjaxResult getInfo(@PathVariable("advertisingId") Integer advertisingId)
    {
        return AjaxResult.success(videoAdvertisingService.selectVideoAdvertisingById(advertisingId));
    }

    /**
     * 新增广告
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:add')")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoAdvertising videoAdvertising)
    {
        return toAjax(videoAdvertisingService.insertVideoAdvertising(videoAdvertising));
    }

    /**
     * 修改广告
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:edit')")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoAdvertising videoAdvertising)
    {
        return toAjax(videoAdvertisingService.updateVideoAdvertising(videoAdvertising));
    }

    /**
     * 删除广告
     */
    @PreAuthorize("@ss.hasPermi('system:advertising:remove')")
    @Log(title = "广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{advertisingIds}")
    public AjaxResult remove(@PathVariable Integer[] advertisingIds)
    {
        return toAjax(videoAdvertisingService.deleteVideoAdvertisingByIds(advertisingIds));
    }
}
